<?php

namespace app\admin\controller;

use think\Controller;
use app\common\model\WechatConfigModel;

class WechatconfigController extends Controller
{
    
    public function index()
    {
        $config=new WechatConfigModel;

        $result=$config->order("created","desc")->find();
        $this->assign("model",$result);
        return view();
    }

    public function update(){
        $config=new WechatConfigModel;
        if($this->request->isAjax())
        {
            $post=$this->request->post();
            $item=$config->order("created","desc")->find();
            if($item){
                unset($post["id"]);
                $result=$item->isUpdate(true)->save($post);
            }else{
                $result=$config->save($post);
            }

            return \zbcjson($result,$result?"修改成功":"修改失败");
        }
        return \zbcjson(false,"未知请求");
    }
}